package com.tz.test.config;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;

/**
 * transactional数据库连接配置
 *
 * @author cmd
 * @date 2020/3/11
 */
@Slf4j
@Configuration
@MapperScan(basePackages = {"com.hexiehome.transactional.dao"})
public class TransactionalSourceConfig {


//    @Value("${spring.datasource.initialSize}")
//    private Integer initialSize;
//
//    @Value("${spring.datasource.minIdle}")
//    private Integer minIdle;
//
//    @Value("${spring.datasource.maxActive}")
//    private Integer maxActive;
//
//    @Value("${spring.datasource.maxWait}")
//    private Integer maxWait;
//
//    @Value("${spring.datasource.validationQuery}")
//    private String validationQuery;
//
//    @Value("${spring.datasource.testWhileIdle}")
//    private boolean testWhileIdle;
//
//    @Bean(name = "transactionalDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.transactional")
//    public DataSource transactionalDataSource() {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setInitialSize(initialSize);
//        dataSource.setMinIdle(minIdle);
//        dataSource.setMaxActive(maxActive);
//        dataSource.setMaxWait(maxWait);
//        return dataSource;
//    }
//
//    @Bean(name = "transactionalSqlSessionFactory")
//    public SqlSessionFactory testSqlSessionFactory(@Qualifier("transactionalDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml"));
//        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
//        configuration.setCallSettersOnNulls(true);
//        bean.setConfiguration(configuration);
//        return bean.getObject();
//    }
//
//    @Bean(name = "transactionalTransactionManager")
//    public DataSourceTransactionManager testTransactionManager(@Qualifier("transactionalDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "transactionalSqlSessionTemplate")
//    public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("transactionalSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
}
